/* : Matrix.java */

public class Matrix {
	private int[][] a;
	Matrix(int n, int m) {
		a = new int[n][m];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				a[i][j] = (int) (Math.random() * 5);
		show();
		}
public Matrix(int n, int m, int k) {
	a = new int[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			a[i][j] = k;
			}
	if(k!=0) show();
	}
public void show() {
	System.out.println("Matrix : " + a.length
			+ " �� " + a[0].length);
	for (int i = 0; i < a.length; i++) {
		for (int j = 0; j < a[0].length; j++)
			System.out.print(a[i][j] + " ");
		System.out.println();
		}
	}
public static void main(String[] args) {
	int n = 2, m = 3, l = 4;
	Matrix p = new Matrix(n, m);
	Matrix q = new Matrix(m, l);
	Matrix r = new Matrix(n, l, 0);
	System.out.println(p.a.length);
	System.out.println(q.a[0].length);
	System.out.println(p.a[0].length);
	
	for (int i = 0; i < p.a.length; i++)
		for (int j = 0; j < q.a[0].length; j++)
			for (int k = 0; k < p.a[0].length; k++)
				r.a[i][j] += p.a[i][k] * q.a[k][j];
	System.out.println("Result: ");             
	r.show();
	}
}
